/* $Id: GridToggleAction.java 37 2009-08-15 23:19:07Z aaron.day $ */
package org.crazydays.gameplan.map.event;


import java.awt.event.ActionEvent;

import javax.swing.Icon;

import org.crazydays.gameplan.Controller;
import org.crazydays.gameplan.swing.AbstractActionWrapper;
import org.crazydays.gameplan.util.IconHelper;
import org.crazydays.i18n.Messages;

/**
 * GridToggle
 */
public class ToggleGrid
    extends AbstractActionWrapper
{
    /** serial version uid */
    public final static long serialVersionUID =
        "$Id: GridToggleAction.java 37 2009-08-15 23:19:07Z aaron.day $"
            .hashCode();

    /** messages */
    public final static Messages MESSAGES = Messages.getInstance();

    /** resource key: name */
    public final static String RESKEY_NAME = "action.GridToggle.name";

    /** icon: tick */
    protected final static String RESKEY_TICK = "action.GridToggle.icon.tick";

    /** icon: tick */
    protected static Icon tick =
        IconHelper.loadIcon(MESSAGES.getMessage(RESKEY_TICK));

    /** icon: cross */
    protected final static String RESKEY_CROSS = "action.GridToggle.icon.cross";

    /** icon: cross */
    protected static Icon cross =
        IconHelper.loadIcon(MESSAGES.getMessage(RESKEY_CROSS));

    /**
     * GridToggle constructor.
     * 
     * @param controller Controller
     */
    public ToggleGrid(Controller controller)
    {
        super(MESSAGES.getMessage(RESKEY_NAME), controller);
    }

    /**
     * Call create map on the create map dialog.
     * 
     * @param event Event
     * @see ActionListener#actionPerformed(ActionEvent)
     */
    public void actionPerformed(ActionEvent event)
    {
        if (controller.toggleGrid()) {
            setIconCross();
        } else {
            setIconTick();
        }
    }

    /**
     * Set icon cross.
     */
    public void setIconCross()
    {
        putValue(SMALL_ICON, cross);
    }

    /**
     * Set icon tick.
     */
    public void setIconTick()
    {
        putValue(SMALL_ICON, tick);
    }
}
